<template>
  <div>
    <!-- ShrimpManagement -->
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>对虾管理</el-breadcrumb-item>
      <el-breadcrumb-item>虾苗进货</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 添加区域 -->
      <el-row
        class="globalHeader"
        style="margin-bottom: 20px; padding-bottom: 45px"
      >
        <el-col :span="4">
          <i class="el-icon-s-help"></i>
          <span>虾苗进货</span>
        </el-col>
        <el-col style="width: 75px; float: right">
          <download-excel
            class="export-excel-wrapper"
            :data="ShrimpList"
            :fields="json_fields"
            name="虾苗进货信息导出.xls"
          >
            <el-button type="success">导出</el-button>
          </download-excel>
        </el-col>
        <el-col style="float: right; width: 100px; margin-right: 10px">
          <el-button
            type="primary"
            @click="addDialogVisible = true"
            :disabled="!permissionVisable.traceability_shrimp_add"
            >添加虾苗</el-button
          >
        </el-col>
      </el-row>

      <!-- 虾苗列表区域 -->
      <el-table :data="ShrimpList" border stripe>
        <!-- :data: 放入数据源 -->
        <!-- border： 加入边框线 -->
        <!-- type="index"： 索引列 -->
        >
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" label-width="170px">
              <el-row style="margin-bottom: 0">
                <el-col :span="12">
                  <el-form-item label="虾苗批次名称" class="down-label">
                    <span>{{ props.row.shrimpBatchName }}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="虾苗品种" class="down-label">
                    <span>{{ props.row.shrimpSpecies }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row style="margin-bottom: 0">
                <el-col :span="12">
                  <el-form-item label="虾苗产地" class="down-label">
                    <span>{{ props.row.shrimpOrigin }}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="虾苗供应商" class="down-label">
                    <span>{{ props.row.shrimpSupplier }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row style="margin-bottom: 0">
                <el-col :span="12">
                  <el-form-item label="虾苗数量/尾" class="down-label">
                    <span>{{ props.row.shrimpNumber }}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="剩余数量/尾" class="down-label">
                    <span>{{ props.row.remainNumber }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row style="margin-bottom: 0">
                <el-col :span="12">
                  <el-form-item label="产量/kg" class="down-label">
                    <span>{{ props.row.yield }}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="创建者" class="down-label">
                    <span>{{ props.row.createBy }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row style="margin-bottom: 0">
                <el-col :span="12">
                  <el-form-item label="创建时间" class="down-label">
                    <span>{{ props.row.createDate }}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="供应商联系电话" class="down-label">
                    <span>{{ props.row.supplierPhone }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-form-item label="质检图片" class="down-label">
                <div class="downBox">
                  <img :src="props.row.qualityInspection" alt />
                  <span class="mask">
                    <span
                      class="mask-icon1"
                      @click="previewInfo(props.row.qualityInspection)"
                    >
                      <i class="el-icon-zoom-in"></i>
                    </span>
                  </span>
                </div>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column
          prop="shrimpBatchName"
          label="虾苗批次名称"
        ></el-table-column>
        <el-table-column
          prop="shrimpSpecies"
          label="虾苗品种"
        ></el-table-column>
        <el-table-column
          prop="shrimpNumber"
          label="虾苗数量/尾"
        ></el-table-column>
        <el-table-column
          prop="remainNumber"
          label="剩余数量/尾"
        ></el-table-column>
        <el-table-column prop="yield" label="产量kg"></el-table-column>
        <el-table-column label="操作" width="130px">
          <template slot-scope="scope">
            <!-- 修改按钮 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showEditDialog(scope.row.id)"
              :disabled="!permissionVisable.traceability_shrimp_update"
            ></el-button>
            <!-- 删除按钮 -->
            <!-- type="danger": 红色警告按钮 -->
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="removeShrimpById(scope.row.id)"
              :disabled="!permissionVisable.traceability_shrimp_delete"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageInfo.pagenum"
        :page-sizes="[4, 6, 8, 10]"
        :page-size="pageInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>

    <!-- echart 视图区域 -->
    <el-card style="margin-top: 1rem" v-show="!!ShrimpName">
      <div style="display: flex">
        <div ref="stockChart" style="width: 52%; height: 376px"></div>
        <div ref="outChart" style="width: 45%; height: 376px"></div>
      </div>
    </el-card>

    <!-- 添加虾苗批次的对话框 -->
    <el-dialog
      title="添加虾苗进货信息"
      :visible.sync="addDialogVisible"
      width="55%"
      @close="addDialogClosed"
    >
      <!-- 内容主体区 -->
      <el-form
        :model="addeForm"
        :rules="addeFormRules"
        ref="addeFormRef"
        label-width="130px"
      >
        <!-- ref:引用，指向本身，用于使用自身的方法 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="批次名称" prop="shrimpBatchName">
              <el-input v-model="addeForm.shrimpBatchName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="虾苗品种" prop="shrimpSpecies">
              <el-select v-model="addeForm.shrimpSpecies" placeholder="请选择">
                <el-option
                  v-for="item in ShrimpSpeciesList"
                  :key="item.id"
                  :value="item.kindName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="虾苗产地" prop="shrimpOrigin">
              <el-input v-model="addeForm.shrimpOrigin"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="虾苗数量/尾" prop="shrimpNumber">
              <el-input-number
                v-model="addeForm.shrimpNumber"
                controls-position="right"
                :min="1"
              ></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="虾苗供应商" prop="shrimpSupplier">
              <el-input v-model="addeForm.shrimpSupplier"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="创建者" prop="createBy">
              <el-select v-model="addeForm.createBy" placeholder="请选择">
                <el-option
                  v-for="(item, i) in personInfoList"
                  :key="i"
                  :value="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="供应商联系电话" prop="supplierPhone">
              <el-input v-model="addeForm.supplierPhone"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12"></el-col>
        </el-row>
        <el-form-item label="质检图片">
          <!-- 回显 -->
          <div v-show="!!addeForm.qualityInspection" class="avatar">
            <img :src="addeForm.qualityInspection" />
            <span class="mask">
              <!-- 放大图片 -->
              <span
                class="mask-icon1"
                @click="preview(addeForm.qualityInspection)"
              >
                <i class="el-icon-zoom-in"></i>
              </span>
              <!-- 删除图片 -->
              <span
                class="mask-icon2"
                @click="deleteImg(addeForm.qualityInspection)"
              >
                <i class="el-icon-delete"></i>
              </span>
            </span>
          </div>
          <el-upload
            class="avatar-uploader"
            action="http://106.75.154.40:9011/base/addPic"
            :show-file-list="false"
            :on-success="addSuccess"
            :before-upload="beforeAdd"
            v-show="!addeForm.qualityInspection"
          >
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <!-- 底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addShrimp">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 修改虾苗信息的对话框 -->
    <el-dialog
      title="修改虾苗信息"
      :visible.sync="aditDialogVisible"
      width="55%"
      @close="aditDialogClosed"
    >
      <!-- 内容主体区 -->
      <el-form
        :model="editForm"
        :rules="editFormRules"
        ref="editFormRef"
        label-width="100px"
      >
        <!-- ref:引用，指向本身，用于使用自身的方法 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="批次名称" prop="shrimpBatchName">
              <el-input v-model="editForm.shrimpBatchName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="创建日期" prop="createDate">
              <el-date-picker
                v-model="editForm.createDate"
                type="datetime"
                placeholder="选择日期时间"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="虾苗品种" prop="shrimpSpecies">
              <el-select v-model="editForm.shrimpSpecies" placeholder="请选择">
                <el-option
                  v-for="item in ShrimpSpeciesList"
                  :key="item.id"
                  :value="item.kindName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="虾苗产地" prop="shrimpOrigin">
              <el-input v-model="editForm.shrimpOrigin"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="虾苗供应商" prop="shrimpSupplier">
              <el-input v-model="editForm.shrimpSupplier"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商电话" prop="supplierPhone">
              <el-input v-model="editForm.supplierPhone"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="剩余数量kg" prop="remainNumber">
              <el-input-number
                v-model="editForm.remainNumber"
                controls-position="right"
                :min="0"
                :max="editForm.shrimpNumber"
              ></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="创建者" prop="createBy">
              <el-select v-model="editForm.createBy" placeholder="请选择">
                <el-option
                  v-for="(item, i) in personInfoList"
                  :key="i"
                  :value="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="产量kg" prop="yield">
              <el-input-number
                v-model="editForm.yield"
                controls-position="right"
                :min="0"
              ></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="虾苗总量/尾" prop="shrimpNumber">
              <el-input-number
                v-model="editForm.shrimpNumber"
                controls-position="right"
                :min="0"
              ></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="工艺图片">
          <!-- 回显 -->
          <div v-show="!!editForm.qualityInspection" class="avatar">
            <img :src="editForm.qualityInspection" />
            <span class="mask">
              <!-- 放大图片 -->
              <span
                class="mask-icon1"
                @click="preview(editForm.qualityInspection)"
              >
                <i class="el-icon-zoom-in"></i>
              </span>
              <!-- 删除图片 -->
              <span
                class="mask-icon2"
                @click="deleteImg(editForm.qualityInspection)"
              >
                <i class="el-icon-delete"></i>
              </span>
            </span>
          </div>
          <el-upload
            class="avatar-uploader"
            action="http://106.75.154.40:9011/processing/addPic"
            :show-file-list="false"
            :on-success="editSuccess"
            :before-upload="beforeAdd"
            v-show="!editForm.qualityInspection"
          >
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <!-- 底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="aditDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editShrimpInfo">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 放大图片 -->
    <el-dialog :visible.sync="isPreview">
      <img :src="previewImg" alt class="previewImg" />
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      token: window.localStorage.getItem('token'),
      // 现有的虾类产量
      ShrimpOutValue: [],

      // 现有的虾类品众
      ShrimpName: [],

      // 数值和名称
      ShrimpValue: [],

      // 基地编号
      baseId: this.$store.baseId,

      // 用于存放人员信息
      personInfoList: [],

      // 虾苗列表
      ShrimpList: [],

      // 虾苗品种列表
      ShrimpSpeciesList: [],

      // 查询到的虾苗批次信息对象，用于修改信息
      editForm: {
        id: '',
        shrimpBatchName: '',
        shrimpSpecies: '',
        shrimpOrigin: '',
        shrimpSupplier: '',
        shrimpNumber: '',
        yield: 0,
        baseId: '',
        createBy: '',
        createDate: '',
        remainNumber: 0,
        // 质检图片
        qualityInspection: '',
        // 供应商电话
        supplierPhone: '',
      },

      // 添加虾苗批次的表单数据
      addeForm: {
        // 虾苗批次名称
        shrimpBatchName: '',
        // 虾苗品种
        shrimpSpecies: '',
        // 虾苗产地
        shrimpOrigin: '',
        // 虾苗供应商
        shrimpSupplier: '',
        // 虾苗数量
        shrimpNumber: '',
        // 基地编号
        baseId: '',
        // 创建者
        createBy: '',
        // 创建时间
        createDate: '',
        // 剩余数量
        remainNumber: '',
        // 质检图片
        qualityInspection: '',
        // 供应商联系电话
        supplierPhone: '',
      },

      // 添加表单的验证规则对象
      addeFormRules: {
        shrimpBatchName: [
          { required: true, message: '请输入虾苗批次名称', trigger: 'blur' },
          {
            min: 2,
            max: 10,
            message: '虾苗批次名称的长度在2~10个字符之间',
            trigger: 'blur',
          },
        ],
        supplierPhone: [
          { required: true, message: '请输入供应商联系电话', trigger: 'blur' },
          {
            min: 2,
            max: 15,
            message: '供应商联系电话的长度在2~15个字符之间',
            trigger: 'blur',
          },
        ],
        shrimpSpecies: [
          { required: true, message: '请输入虾苗品种', trigger: 'blur' },
        ],
        shrimpOrigin: [
          { required: true, message: '请输入虾苗产地', trigger: 'blur' },
        ],
        shrimpSupplier: [
          { required: true, message: '请输入虾苗供应商', trigger: 'blur' },
          {
            min: 2,
            max: 10,
            message: '虾苗供应商名称的长度在2~10个字符之间',
            trigger: 'blur',
          },
        ],
        shrimpNumber: [
          { required: true, message: '请输入虾苗数量', trigger: 'blur' },
        ],
        createBy: [
          { required: true, message: '请输入创建者', trigger: 'blur' },
        ],
      },

      // 修改表单的验证规则对象
      editFormRules: {
        shrimpBatchName: [
          { required: true, message: '请输入虾苗批次名称', trigger: 'blur' },
          {
            min: 2,
            max: 10,
            message: '虾苗批次名称的长度在2~10个字符之间',
            trigger: 'blur',
          },
        ],
        shrimpSpecies: [
          { required: true, message: '请输入虾苗品种', trigger: 'blur' },
        ],
        shrimpOrigin: [
          { required: true, message: '请输入虾苗产地', trigger: 'blur' },
        ],
        shrimpSupplier: [
          { required: true, message: '请输入虾苗供应商', trigger: 'blur' },
          {
            min: 2,
            max: 10,
            message: '虾苗供应商名称的长度在2~10个字符之间',
            trigger: 'blur',
          },
        ],
        shrimpNumber: [
          { required: true, message: '请输入虾苗数量', trigger: 'blur' },
        ],
        createBy: [
          { required: true, message: '请输入创建者', trigger: 'blur' },
        ],
        createDate: [
          { required: true, message: '请输入创建时间', trigger: 'blur' },
        ],
        yield: [{ required: true, message: '请输入产量', trigger: 'blur' }],
      },
      // 放大图片路径
      previewImg: '',

      // 控制放大面板的显示和隐藏
      isPreview: false,

      // 控制添加虾苗的开关
      addDialogVisible: false,

      // 控制修改虾苗信息对话框的显示和隐藏
      aditDialogVisible: false,

      // 用于控制分页的当前页码和条数
      pageInfo: {
        // 当前页码
        pagenum: 1,
        // 每页显示条数
        pagesize: 4,
      },
      // 总条数
      total: 0,

      // 导出表格信息
      json_fields: {
        虾苗批次名称: 'shrimpBatchName',
        虾苗品种: 'shrimpSpecies',
        虾苗产地: 'shrimpOrigin',
        虾苗供应商: 'shrimpSupplier',
        供应商电话: 'supplierPhone',
        '虾苗数量/尾': 'shrimpNumber',
        '剩余数量/尾': 'remainNumber',
        产量kg: 'yield',
        创建者: 'createBy',
        创建时间: 'createDate',
      },

      json_meta: [
        [
          {
            ' key ': ' charset ',
            ' value ': ' utf- 8 ',
          },
        ],
      ],
    }
  },
  created() {
    this.getShrimpList()
    this.getAllShrimpList().then(() => {
      this.getStockChartData()
      this.getOutChartData()
    })
    this.getShrimpSpeciesList()
    this.getPersonInfoList()
  },
  computed: {
    ...mapState(['permissionVisable']),
    // 虾苗进货量图表格
    stockOption() {
      let that = this
      console.log(that.ShrimpName)
      let option = {
        title: {
          text: '虾苗进货量',
          subtext: '比例图',
          left: 'center',
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)',
        },
        legend: {
          orient: 'vertical',
          left: 10,
          data: that.ShrimpName,
        },
        series: [
          {
            name: '虾苗进货量',
            type: 'pie',
            selectedMode: 'single',
            radius: [0, '30%'],

            label: {
              position: 'inner',
            },
            labelLine: {
              show: false,
            },
            data: that.ShrimpValue,
          },
          {
            name: '虾苗进货量',
            type: 'pie',
            radius: ['40%', '55%'],
            label: {
              formatter: '{a|{a}}{abg|}\n{hr|}\n  {b|{b}：}{c}  {per|{d}%}  ',
              backgroundColor: '#eee',
              borderColor: '#aaa',
              borderWidth: 1,
              borderRadius: 4,
              // shadowBlur:3,
              // shadowOffsetX: 2,
              // shadowOffsetY: 2,
              // shadowColor: '#999',
              // padding: [0, 7],
              rich: {
                a: {
                  color: '#999',
                  lineHeight: 16,
                  align: 'center',
                },
                // abg: {
                //     backgroundColor: '#333',
                //     width: '100%',
                //     align: 'right',
                //     height: 22,
                //     borderRadius: [4, 4, 0, 0]
                // },
                hr: {
                  borderColor: '#aaa',
                  width: '100%',
                  borderWidth: 0.5,
                  height: 0,
                },
                b: {
                  fontSize: 13,
                  lineHeight: 33,
                },
                per: {
                  color: '#eee',
                  backgroundColor: '#334455',
                  padding: [2, 4],
                  borderRadius: 2,
                },
              },
            },
            data: that.ShrimpValue,
          },
        ],
      }
      return option
    },
    // 虾苗产量图表
    outOption() {
      let that = this
      let option = {
        title: {
          text: '虾苗产量',
          subtext: '比例图',
          left: 'center',
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)',
        },
        legend: {
          orient: 'vertical',
          right: 10,
          top: 100,
          data: that.ShrimpName,
        },
        series: [
          {
            name: '虾苗产量',
            type: 'pie',
            radius: [30, 110],
            center: ['50%', '50%'],
            roseType: 'area',
            data: that.ShrimpOutValue,
          },
        ],
      }
      return option
    },
  },
  methods: {
    // 获取进货虾类比例————描绘进货量图标
    getStockChartData() {
      const chart = this.$refs.stockChart
      if (chart) {
        const myChart = this.$echarts.init(chart)
        console.log(this.stockOption)
        myChart.setOption(this.stockOption)
        window.addEventListener('resize', function () {
          myChart.resize()
        })
      }
      this.$on('hook:destroyed', () => {
        window.removeEventListener('resize', function () {
          myChart.resize()
        })
      })
    },

    // 描绘产量图表
    getOutChartData() {
      // 获取页面中的描绘对象
      const chart = this.$refs.outChart
      if (chart) {
        // 初始化echart实例对象
        const myChart = this.$echarts.init(chart)
        // 使用设置的数据显示图表
        myChart.setOption(this.outOption)
        window.addEventListener('resize', function () {
          myChart.resize
        })
      }
      this.$on('hook:destroyed', () => {
        window.removeEventListener('resize', function () {
          myChart.resize
        })
      })
    },

    // 获取所有虾苗列表
    // 处理echart数据
    async getAllShrimpList() {
      const { data: res } = await this.$http.post(`/shrimpManagement/search`, {
        baseId: this.baseId,
      })
      var shrimpList = res.data
      // 获取现有的虾类品众
      var arr = []
      // 带有数据的shrimp值
      var arr1 = []
      // 保存名字及其产量
      var arr2 = []
      shrimpList.forEach((item) => {
        arr.push(item.shrimpSpecies)
      })
      // 去重
      arr = arr.filter(function (item, index, array) {
        return array.indexOf(item) === index
      })
      // 循环将已经去重的名字赋予emptyObj，并加入arr1
      arr.forEach((item) => {
        // 空对象，存值
        let emptyObj = { name: '', value: 0 }
        let emptyOut = { name: '', value: 0 }
        emptyObj.name = item
        emptyOut.name = item
        arr1.push(emptyObj)
        arr2.push(emptyOut)
      })
      shrimpList.forEach((item) => {
        arr1.forEach((item1) => {
          if (item.shrimpSpecies === item1.name) {
            item1.value += item.shrimpNumber
          }
        })
        arr2.forEach((item2) => {
          if (item.shrimpSpecies === item2.name) {
            item2.value += item.yield
          }
        })
      })
      this.ShrimpName = arr
      this.ShrimpValue = arr1
      this.ShrimpOutValue = arr2
    },

    /* 图片相关的方法 */
    // 查看资料放大图片
    previewInfo(src) {
      this.isPreview = true
      this.previewImg = src
    },
    // 放大图片
    preview(Pic) {
      this.isPreview = true
      this.previewImg = Pic
    },
    // 删除图片
    deleteImg(url) {
      this.addeForm.qualityInspection = ''
      this.editForm.qualityInspection = ''
      $.ajax({
        url: 'http://106.75.154.40:9011/base/delPic',
        type: 'POST',
        data: {
          _method: 'DELETE',
          delUrl: url,
        },
      })
      this.$message.success('图片删除成功！！')
    },

    // 添加图片上传成功函数
    addSuccess(res, file) {
      this.addeForm.qualityInspection = res.data
    },

    // 修改图片上传成功函数
    editSuccess(res, file) {
      this.editForm.qualityInspection = res.data
    },

    // 图片上传前判断
    beforeAdd(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isLt2M
    },
    /* 结束 */

    // 获取人员信息
    async getPersonInfoList() {
      const { data: res } = await this.$http.get(
        `${this.$limit}/user/getBaseMember`,
        {
          headers: {
            Authorization: this.token,
          },
        }
      )
      this.personInfoList = res.data
      // console.log(this.personInfoList)
    },

    // 获取虾苗列表
    async getShrimpList() {
      const { data: res } = await this.$http.post(
        `/shrimpManagement/search/${this.pageInfo.pagenum}/${this.pageInfo.pagesize}`,
        {
          baseId: this.baseId,
        }
      )
      console.log(res)
      if (res.code !== 20000) {
        return this.$message.error('获取虾苗列表失败！！')
      }
      this.ShrimpList = res.data.rows
      this.total = res.data.total
    },

    // 获取虾苗品种列表
    async getShrimpSpeciesList() {
      const { data: res } = await this.$http.get('/shrimpKind')
      console.log(res)
      if (res.code !== 20000) {
        return this.$message.error('获取虾苗列表失败！！')
      }
      this.ShrimpSpeciesList = res.data
      console.log(this.ShrimpSpeciesList)
    },

    // 监听添加用户对话框的关闭事件,关闭时对表单进行重置
    addDialogClosed() {
      // 表单方法：resetFields：对整个表单进行重置，将所有字段值重置为初始值并移除校验结果
      this.$refs.addeFormRef.resetFields()
      // 重置图片
      this.addeForm.qualityInspection = ''
    },

    // 监听修改用户对话框的关闭事件
    aditDialogClosed() {
      this.$refs.editFormRef.resetFields()
    },

    // 监听pagesize(每页显示条数)改变事件
    handleSizeChange(newSize) {
      this.pageInfo.pagesize = newSize
      this.getShrimpList()
    },

    // 监听页码值改变的事件
    handleCurrentChange(newPage) {
      this.pageInfo.pagenum = newPage
      this.getShrimpList()
    },

    // 点击按钮，添加虾苗信息
    addShrimp() {
      // 先进行表单的预校验
      this.$refs.addeFormRef.validate(async (valid) => {
        // 表单自身方法：validate：进行表单预验证，放回验证结果，用valid接收
        if (!valid) return false
        // 成功后，可以发起添加用户的网络请求
        // 调用添加用户接口
        this.addeForm.baseId = this.baseId
        var date = new Date()
        this.addeForm.createDate = `${date.getFullYear()}-${
          date.getMonth() + 1
        }-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
        const { data: res } = await this.$http.post(
          '/shrimpManagement',
          this.addeForm
        )
        console.log(res)
        if (res.code !== 20000) {
          return this.$message.error('批次名称重复！！')
        }
        this.$message.success('添加虾苗成功!!')
        // 隐藏添加的对话框
        this.addDialogVisible = false
        // 隐藏添加的对话框
        this.addDialogVisible = false
        // 成功后新增，需要刷新用户列表
        this.getShrimpList()
        // 更新图表
        this.getAllShrimpList().then(() => {
          this.getStockChartData()
          this.getOutChartData()
        })
      })
    },

    // 展示虾苗修改的对话框
    async showEditDialog(id) {
      // 调用根据ID查询用户信息接口
      const { data: res } = await this.$http.get('/shrimpManagement/' + id)
      console.log(res)
      if (res.code !== 20000) {
        return this.$message.error('查询虾苗信息失败！！')
      }
      this.editForm = res.data
      this.aditDialogVisible = true
    },

    // 修改虾苗信息并提交
    editShrimpInfo() {
      // 先进行表单的预验证
      this.$refs.editFormRef.validate(async (valid) => {
        if (!valid) return false
        // 正确，则会发起修改用户信息的请求
        var date = new Date(this.editForm.createDate)
        this.editForm.createDate = `${date.getFullYear()}-${
          date.getMonth() + 1
        }-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
        console.log(this.editForm.createDate)
        const { data: res } = await this.$http.put(
          '/shrimpManagement/' + this.editForm.id,
          {
            qualityInspection: this.editForm.qualityInspection,
            shrimpBatchName: this.editForm.shrimpBatchName,
            createDate: this.editForm.createDate,
            shrimpSpecies: this.editForm.shrimpSpecies,
            shrimpOrigin: this.editForm.shrimpOrigin,
            shrimpSupplier: this.editForm.shrimpSupplier,
            shrimpNumber: this.editForm.shrimpNumber,
            baseId: this.editForm.baseId,
            createBy: this.editForm.createBy,
            remainNumber: this.editForm.remainNumber,
            yield: this.editForm.yield,
            supplierPhone: this.editForm.supplierPhone,
          }
        )
        if (res.code !== 20000) {
          return this.$message.error('更新对虾信息失败！！')
        }
        // 关闭对话框
        this.aditDialogVisible = false
        // 刷新用户列表
        this.getShrimpList()
        // 更新图表
        this.getAllShrimpList().then(() => {
          this.getStockChartData()
          this.getOutChartData()
        })
        // 提
        // 提示修改成功
        this.$message.success('更新对虾信息成功！！')
      })
    },

    // 根据id删除对应的虾苗信息
    async removeShrimpById(id) {
      // 弹框询问是否删除数据
      // 前提：在elementUI中挂载confirm
      // （提示消息，标题文本，｛确认按钮的文本，取消按钮的文本，提示的类型｝）
      const confirmResult = await this.$confirm(
        '此操作将永久删除该虾苗信息, 是否继续?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }
        // .catch 用于捕获错误返回给confirmResult
      ).catch((err) => {
        return err
      })
      // 如果用户确认删除，则返回值为字符串 confirm
      // 如果用户取消了删除， 则返回值为字符串 cancel
      if (confirmResult !== 'confirm') {
        // this.$message.info: 灰色提示框
        return this.$message.info('已取消删除')
      }
      const { data: res } = await this.$http.delete('/shrimpManagement/' + id)
      console.log(res)
      if (res.code !== 20000) {
        return this.$message.error('删除虾苗信息失败')
      }
      this.$message.success('删除虾苗信息成功！！')
      this.getShrimpList()
      this.getAllShrimpList().then(() => {
        this.getStockChartData()
        this.getOutChartData()
      })
    },
  },
}
</script>

<style lang="less">
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatarBox {
  position: relative;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  img {
    width: 100%;
    height: 100%;
    border-radius: 6px;
  }
  .mask-icon1,
  .mask-icon2 {
    display: none;
    color: #fff;
    font-size: 30px;
    cursor: pointer;
  }
}
.avatar:hover .mask {
  position: absolute;
  width: 178px;
  height: 178px;
  top: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 10;
  border-radius: 6px;
}
.avatar:hover .mask-icon1 {
  display: block;
  position: absolute;
  top: 62px;
  left: 45px;
}
.avatar:hover .mask-icon2 {
  display: block;
  position: absolute;
  top: 62px;
  left: 95px;
}
.mask-icon1:hover,
.mask-icon2:hover {
  color: rgb(165, 163, 163);
}
</style>
